#include <stdio.h>
#include <string.h>

char *file_path_name_paste(char *dest, const char* path, const char* name) {
    if (path[strlen(path)-1] == '/')
        sprintf(dest, "%s%s", path, name);
    else 
        sprintf(dest, "%s/%s", path, name);
    return dest;
}

char *strrstr(const char *haystack, const char *needle) {
    if (haystack == NULL || needle == NULL || *needle == '\0') {
        return NULL; // 处理空指针或空子串
    }

    char *last_occurrence = NULL;
    char *current_pos = (char *)haystack;

    // 循环查找所有匹配位置
    while ((current_pos = strstr(current_pos, needle)) != NULL) {
        last_occurrence = current_pos; // 更新最后一次找到的位置
        current_pos++; // 移动到下一个字符继续搜索
    }

    return last_occurrence;
}

char *get_file_path_relative(char *dest, char *path) {
    char *last = strrstr(path, "/");
    if (last) {
        strncpy(dest, path, last-path);
        dest[last-path] = 0;
    } else {
        dest[0] = 0;
    }
    return dest;
}
